﻿using Riba.MVVMSL;

namespace MVVMtutorial
{
	public class ChildWindow1ViewModel : ViewModelBase
	{
		public RelayCommand CommandOk { get; private set; }

		public ChildWindow1ViewModel()
		{
			ExchangeDataAvailable += ChildWindow1ViewModel_ExchangeDataAvailable;

			CommandOk = new RelayCommand
				(
					handler =>
						{
							if (Callback != null)
								Callback(this, ExchangeData);

							RaiseCloseChildWindowView();
						}
				);

			ChildWindowClosed += ChildWindow1ViewModel_ChildWindowClosed;
		}

		void ChildWindow1ViewModel_ChildWindowClosed(object sender, ChildWindowClosedEventArgs e)
		{
			RaiseShowMsgBox(new ShowMsgBoxEventArgs(string.Format("DialogResult={0}", e.DialogResult), ""));
		}

		void ChildWindow1ViewModel_ExchangeDataAvailable(object sender, ExchangeDataAvailableEventArgs e)
		{
			CommandOk.IsEnabled = true;
		}
	}
}
